package cn.ydt.ydt.sso.webapi.repository.impl;

import cn.ydt.ydt.sso.webapi.repository.IRedisRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisRepositoryImpl implements IRedisRepository {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;


    @Override
    public void saveToken(Long id, String token) {
        String userKey = KEY_USER_TOKEN+id.toString();
        redisTemplate.opsForValue().set(userKey,token);
    }

    @Override
    public String getToken(Long id) {
        String token = (String) redisTemplate.opsForValue().get(id.toString());
        return token;
    }

    @Override
    public void saveEmptyValue(Long id) {
        String key = KEY_USER_TOKEN+id.toString();
        redisTemplate.opsForValue().set(key,null,30, TimeUnit.SECONDS);
    }
}
